package com.tesis_2.UI;

import java.io.UnsupportedEncodingException;
import java.text.ParseException;

import org.json.JSONException;

import com.example.t2_clientback.R;
import com.example.t2_clientback.R.layout;
import com.example.t2_clientback.R.menu;
import com.tesis_2.BL.BLReservas;
import com.tesis_2.BL.BLRestaurants;
import com.tesis_2.MO.MORestaurant;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;

public class UIRegistrarRestaurante extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_uiregistrar_restaurante);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater()
				.inflate(R.menu.activity_uiregistrar_restaurante, menu);
		return true;
	}
	
	
	public boolean onOptionsItemSelected(MenuItem item) {
	    
		Intent intent; 
		
		switch (item.getItemId()) 
	    {
	        case R.id.optGuardar_registrar_restaurant:
	        	
			
				saveRestaurant();
			
	        	//intent = new Intent(this, UILocales.class);
				//intent.putExtra("nRest", position);
				//startActivity(intent);
	        break;
	        
	        default: 
	        	
	        break;
	    }
	    return false;
	} 
	
	public void saveRestaurant()
	{
		String nombre = ((EditText) findViewById(R.id.txtNombre_registrar_restaurante)).getText().toString();
		String cocina = ((EditText) findViewById(R.id.txtCocina_registrar_restaurante)).getText().toString();
		String descripcion = ((EditText) findViewById(R.id.txtDescripcion_registrar_restaurante)).getText().toString();
		String telefono = ((EditText) findViewById(R.id.txtTelefono_registrar_restaurante)).getText().toString();
		String correo = ((EditText) findViewById(R.id.txtCorreo_registrar_restaurante)).getText().toString();
		
		MORestaurant objRest = new MORestaurant();
		
		objRest.setName(nombre.replace(" ", "%20"));
		objRest.setCuisine(cocina.replace(" ", "%20"));
		objRest.setDescr(descripcion.replace(" ", "%20"));
		objRest.setPhone(telefono.replace(" ", "%20"));
		objRest.setEmail(correo.replace(" ", "%20"));
		objRest.setEmail(correo.replace(".", "-"));
		
		try {
			objRest = BLRestaurants.createRest(objRest);
			finish();
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}
	

}
